// pages/aiQa/aiQa.js
Page({
  data: {
    messages: [],
    inputValue: ''
  },

  onInput: function(e) {
    this.setData({
      inputValue: e.detail.value
    });
  },

  sendMessage: function() {
    const userMessage = {
      id: Date.now(),
      sender: '用户',
      content: this.data.inputValue
    };

    this.setData({
      messages: [...this.data.messages, userMessage],
      inputValue: ''
    });

    // 模拟AI回复
    setTimeout(() => {
      const aiMessage = {
        id: Date.now(),
        sender: 'AI',
        content: '这是AI的回复：' + this.data.inputValue
      };
      this.setData({
        messages: [...this.data.messages, aiMessage]
      });
    }, 1000);

    // 滚动到底部
    this.scrollToBottom();
  },

  onScrollToLower: function() {
    this.scrollToBottom();
  },

  scrollToBottom: function() {
    this.selectComponent('.chat-container').scrollToLower();
  }
});